<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>N6_1F储位管理</title>
  <%@include file="/WEB-INF/common/css.jsp"%>
  <style>
  	#listtable thead tr th, #listtable tbody tr td{
  		text-align: center;
  	}
  	.selectstyle{
  		margin-top: 10px;
  	}
  </style>
  <%@include file="/WEB-INF/common/topjs.jsp"%>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
  
  <%@include file="/WEB-INF/common/jsp/header.jsp"%>
  
  <div class="layui-body" style="left: 10px;padding-right: 50px;padding-left: 50px">
    <!-- 内容主体区域 -->
    	<br><br>
    	<form class="layui-form" lay-filter="selectForm">
    		<div class="layui-form-item">
			    <div class="layui-input-inline selectstyle">
			      <select id="machine" name="machine" lay-filter="machine">
			      </select>
			    </div>
			    <div class="layui-input-inline selectstyle">
			      <select id="item" name="item" lay-filter="item">
			      </select>
			    </div>
			    <div class="layui-input-inline selectstyle">
			      <select id="gjehState" name="gjehState" lay-filter="gjehState">
			      </select>
			    </div>
			    <div class="layui-input-inline selectstyle">
			      <select id="tempputState" name="tempputState" lay-filter="tempputState">
			      </select>
			    </div>
			    <div class="layui-input-inline selectstyle">
			      <select id="liaohao" name="liaohao" lay-filter="tempputState">
			      </select>
			    </div>
			    <div class="layui-input-inline selectstyle">
			      <select id="gjNo" name="gjNo" lay-filter="gjNo">
			      </select>
			    </div>
			    <div class="layui-input-inline selectstyle">
			      <select id="daChuwei" name="daChuwei" lay-filter="daChuwei">
			      </select>
			    </div>
			    <div class="layui-input-inline selectstyle">
			      <select id="xiaoChuwei" name="xiaoChuwei" lay-filter="xiaoChuwei">
			      </select>
			    </div>
			</div>
    	</form>
    	<hr>
    	<p style="font-size: 32px;font-weight: bold;color: #5f615f" id="totalShow">Total: 0</p>
    	<hr>
    	<p>
    		<button class="layui-btn" onclick="exportExcel()">导出</button>
    	</p>
    	<hr>
		<table class="layui-table" border="1" id="listtable">
			<thead>
				<tr class=""  style="background: #399ddb;color: #fff">
					<th>机种</th>
					<th>类型</th>
					<th>状态</th>
					<th>暂放状态</th>
					<th>钢架编号</th>
					<th>大储位</th>
					<th>小储位</th>
					<th>料号</th>
					<th>SN</th>
					<th>Input时间</th>
				</tr>
			</thead>
			<tbody id="listshow">

			</tbody>
		</table>
		<div id="pager"></div>
  </div>
  
  <%@include file="/WEB-INF/common/jsp/footer.jsp"%>
  
</div>
<%@include file="/WEB-INF/common/bottomjs.jsp"%>
<script>

var page = 1, size = 10;

$(function(){
	findMachines();
	findItems();
	findGjehStates();
	findTempputStates();
	findLiaohao();

	findGanjia();
	showData();
})

function bindEvent(filter){
	showData();
	layui.form.on("select("+filter+")", function(data){
		showData();
	})
}

function exportExcel(){
	
	$.ajax({
		url:"${base}/api/dataDetails/auto/exportExcel.api",
    	type: "post",
    	data: {
    		machine:$("#machine").val()
    		, item:$("#item").val()
    		, gjehState:$("#gjehState").val()
    		, tempputState:$("#tempputState").val()
    		, liaohao: $("#liaohao").val()
    		, gjNo: $("#gjNo").val()
    		, daChuwei: $("#daChuwei").val()
    		, xiaoChuwei: $("#xiaoChuwei").val()
    	},
    	headers: Apicheck.getHeaders(),
    	success: function(result){
    		if(result.code == 1001){
    			location.href="${base}/api/dataDetails/auto/downloadExcel?filename=" + result.data;
    		}else{
    			var hqlhHtml = "<img src='${base}/assets/image/alertemoj/huosudenglv.gif' /><br>";
    			hqlhHtml += "<h3 style='text-align: center;font-size: 23px;margin-top: 27px;color:#149e5e;font-weight: bold'>"+result.msg+"</h3>";
    			var hqlhAreat = layer.open({
    				title : '消息提示',
    				content : hqlhHtml,
    			});
    		}
    	}
	});
}

function showData(){
	$.ajax({
		url:"${base}/api/dataDetails/auto/list.api",
    	type: "post",
    	data: {
			page: page
			, size: size
    		, machine:$("#machine").val()
    		, item:$("#item").val()
    		, gjehState:$("#gjehState").val()
    		, tempputState:$("#tempputState").val()
    		, liaohao: $("#liaohao").val()
    		, gjNo: $("#gjNo").val()
    		, daChuwei: $("#daChuwei").val()
    		, xiaoChuwei: $("#xiaoChuwei").val()
    	},
    	headers: Apicheck.getHeaders(),
    	success: function(result){
    		var tbody = "";
    		var list = result.data.list;
    		for(var i = 0; i < list.length; i ++){
    			tbody += "<tr>";
    			tbody += "<td>" + list[i].dataMachine + "</td>";
    			tbody += "<td>" + list[i].dataItem + "</td>";
    			tbody += "<td>" + list[i].dataGJEHState + "</td>";
    			tbody += "<td>" + list[i].dataTempputState + "</td>";
    			tbody += "<td>" + list[i].gjNo + "</td>";
    			tbody += "<td>" + list[i].daChuwei + "</td>";
    			tbody += "<td>" + list[i].xiaoChuwei + "</td>";
    			tbody += "<td>" + list[i].liaohao + "</td>";
    			tbody += "<td>" + list[i].sn + "</td>";
    			tbody += "<td>" + list[i].updateTime + "</td>";
    			tbody += "</tr>";
    		}
    		$("#listshow").html(tbody);
    		$("#totalShow").html("Total: " + result.data.pager.recordCount);
    		layui.laypage.render({
    			  elem: $('#pager')
    			  , count: result.data.pager.recordCount
    			  , curr: result.data.pager.pageNumber
    			  , jump: function(obj, first){
    			    page = obj.curr;
    			    size = obj.limit;
    			    //首次不执行
    			    if(!first){
    			    	showData();
    			    }
    			}
    		});
    	}
	});
}
function findMachines() {
	$.ajax({
		url : "${base}/api/dataSummary/findMachinesByAuto.api",
		type : "post",
		headers: Apicheck.getHeaders(),
		success : function(result) {
			$("#machine").html("");
			$("#machine").append("<option value=''></option>");
			var list = result.data;
			for (var i = 0; i < list.length; i++) {
				$("#machine").append(
						"<option value='"+list[i].name+"'>"
								+ list[i].name + "</option>");
			}
			layui.form.render("select", "selectForm");
			bindEvent("machine");
		}
	});
}
function findItems() {
	$.ajax({
		url : "${base}/api/dataSummary/findItemsByAuto.api",
		type : "post",
		headers: Apicheck.getHeaders(),
		success : function(result) {
			$("#item").html("");
			$("#item").append("<option value=''></option>");
			var list = result.data;
			for (var i = 0; i < list.length; i++) {
				$("#item").append(
						"<option value='"+list[i].name+"'>"
								+ list[i].name + "</option>");
			}
			layui.form.render("select", "selectForm");
			bindEvent("item");
		}
	});
}
function findGjehStates() {
	$.ajax({
		url : "${base}/api/dataSummary/findGjehStatesByAuto.api",
		type : "post",
		data : {
			page : 1,
			size : 1000
		},
		headers: Apicheck.getHeaders(),
		success : function(result) {
			$("#gjehState").html("");
			$("#gjehState").append("<option value=''></option>");
			var list = result.data;
			for (var i = 0; i < list.length; i++) {
				$("#gjehState").append(
						"<option value='"+list[i].name+"'>"
								+ list[i].name + "</option>");
			}
			layui.form.render("select", "selectForm");
			bindEvent("gjehState");
		}
	});
}
function findTempputStates() {
	$.ajax({
		url : "${base}/api/dataSummary/findTempputStatesByAuto.api",
		type : "post",
		data : {
			page : 1,
			size : 1000
		},
		headers: Apicheck.getHeaders(),
		success : function(result) {
			$("#tempputState").html("");
			$("#tempputState").append("<option value=''></option>");
			var list = result.data;
			for (var i = 0; i < list.length; i++) {
				$("#tempputState").append(
						"<option value='"+list[i].name+"'>"
								+ list[i].name + "</option>");
			}
			layui.form.render("select", "selectForm");
			bindEvent("tempputState");
		}
	});
}

function findLiaohao() {
	$.ajax({
		url : "${base}/api/dataSummary/findLiaohaosByAuto.api",
		type : "post",
		headers: Apicheck.getHeaders(),
		success : function(result) {
			$("#liaohao").html("");
			$("#liaohao").append("<option value=''></option>");
			var list = result.data;
			for (var i = 0; i < list.length; i++) {
				$("#liaohao").append(
						"<option value='"+list[i]+"'>"
								+ list[i] + "</option>");
			}
			layui.form.render("select", "selectForm");
			bindEvent("liaohao");
		}
	});
}

function findGanjia() {
	$.ajax({
		url : "${base}/api/gangjia/list.api",
		type : "post",
		data : {
			page : 1,
			size : 1000
		},
		headers: Apicheck.getHeaders(),
		success : function(result) {
			$("#gjNo").html("");
			$("#gjNo").append("<option value=''></option>");
			var list = result.data.list;
			for (var i = 0; i < list.length; i++) {
				$("#gjNo").append(
						"<option value='"+list[i].name+"'>"
								+ list[i].name + "</option>");
			}
			layui.form.render("select", "selectForm");
			
			if(list && list.length > 0){
				layui.form.on("select(gjNo)", function(data) {
					$("#daChuwei").html("");
					$("#xiaoChuwei").html("");
					findDachuwei();
				});
				findDachuwei();
			}else{
				bindEvent("gjNo");
			}
		}
	});
}

function findDachuwei() {
	$.ajax({
		url : "${base}/api/dachuwei/findByGanjias.api",
		type : "post",
		data : {
			ganjiaName : $("#gjNo").val()
		},
		headers: Apicheck.getHeaders(),
		success : function(result) {
			$("#daChuwei").html("");
			$("#daChuwei").append("<option value=''></option>");
			if(result.data){
				var list = result.data.dachuweis;
				for (var i = 0; i < list.length; i++) {
					$("#daChuwei").append(
							"<option value='"+list[i].name+"'>"
									+ list[i].name + "</option>");
				}
				layui.form.render("select", "selectForm");
				if(list && list.length > 0){
					layui.form.on("select(daChuwei)", function(data) {
						$("#xiaoChuwei").html("");
						findXiaochuwei();
					});
					findXiaochuwei();
				}else{
					bindEvent("daChuwei");
				}
			}else{
				bindEvent("daChuwei");
			}
			
		}
	});
}
function findXiaochuwei() {
	$.ajax({
		url : "${base}/api/xiaochuwei/findByDachuwei.api",
		type : "post",
		data : {
			dachuweiName : $("#daChuwei").val()
		},
		headers: Apicheck.getHeaders(),
		success : function(result) {
			$("#xiaoChuwei").html("");
			$("#xiaoChuwei").append("<option value=''></option>");
			if(result.data){
				var list = result.data.xiaochuwei;
				for (var i = 0; i < list.length; i++) {
					$("#xiaoChuwei").append(
							"<option value='"+list[i].name+"'>"
									+ list[i].name + "</option>");
				}
				layui.form.render("select", "selectForm");
			}
			bindEvent("xiaoChuwei");
		}
	});
}
</script>
</body>
</html>